<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<script src="assets/scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script type="text/javascript">
		var tmpID;
		
		function selectCategory( index, value ){
			
			tmpID = index;
			
			var url = './get_products.php?id=' + value;
			start_ajax( url, 'reloadProducts');
			return false;
		}
		
		/* Ajax通信 ***********************************************************************************/
		var start_ajax = function( strURL, strJSONP ){
			//ajax通信開始
			$.ajax({
				type: 'GET',
				url: strURL,
				dataType: 'jsonp',
				jsonp: strJSONP
			});
			return false;
		}
		// JSONPで取得したデータをcategory-listに追加
		var reloadProducts = function(jsonData) {
			
			var ctl = '#products' + tmpID;
			
			$(ctl + ' option').each( function(){
				$(this).remove();
			});
			$(jsonData.services).each( function(){
				var str = "<option value='" + this.id + "'>"+ this.name + "</option>";
				$(ctl).append(str);
			});
		}
		$(function() {
			var costs = {};
{{ foreach from=$costs key=k item=v }}costs[{{ $k }}]={{ $v }};{{ /foreach }}
			// メッセージのフェード
			$('.message').fadeIn("slow");
			// 製品変更
			$('.prodName select').change(function(){
				var cost = costs[$(this).val()];
				var amount = $(this).parent().parent().find('.calc').val();
				var target = $(this).parent().parent().find('.subTotal');
				if( $(this).val() != 0 && !isNaN(amount) && amount != ''){
					target.text(amount * cost);
				}else{
					target.text('');
				}
			});
			// 数量入力
			$('.calc').blur(function(){
				var target = $(this).parent().parent().find('.subTotal');
				var amount = $(this).val();
				var targetCost = $(this).parent().parent().find('.prodName select');
				var cost = targetCost.val();
				if(isNaN(amount)){
					alert('半角数字で入力してください');
					target.text('');
				}else if( cost != 0 ){
					target.text(amount * costs[cost]);
				}else{
					target.text('');
				}
				
			});
			/*
			$('select[name="category[1]"]').change(function(){
				alert('a');
			});
			*/
			// 印刷画面を開く
			$('.btn_preview').click(function(){
				var url = './preview/sample.php?id=' + {{ $forms.id }};
				window.open(url, 'printpreview');
			});
			// コピーして新規作成
			$('.btn_copy').click(function(){
				var url = './sample_form.php?id=' + {{ $forms.id }} + '&mode=copy';
				document.location = url;
			});
			// 更新
			$('.btn_edit').click(function(){
				var url = './sample_form.php?id=' + {{ $forms.id }};
				document.location = url;
			});
			// 承認
			$('.btn_approve_ok').click(function(){
				if( confirm('承認してよろしいですか？') ){
					document.fm.status.value = 3;
					document.fm.submit();
				}
			});
			// 非承認
			$('.btn_approve_ng').click(function(){
				if( confirm('却下してよろしいですか？') ){
					document.fm.status.value = 4;
					document.fm.submit();
				}
			});
			
		});
		// 印刷画面を開く
		function open_preview(){
			var url = './preview/sample.php?id=' + {{ $forms.id }};
			window.open(url, 'printpreview');
		}
		</script>
	</head>
	<body id="">
{{ php }} include( MENU_FILE ); {{ /php }}
		<div id="header" class="clearfix"><div class="wrapper">
			<h1><a href="./">コントロールパネル</a></h1>
			<form id="form_logout" action="logout.php" method="post"><p>{{ $login.staff_name }} <input type="submit" id="button_logout" value="ログアウト" /></p></form>
		</div></div>
		<div id="container"><div class="wrapper">
			<h2>サンプル依頼</h2>
			<ul class="submenu clearfix">
				<li><a href="sample_index.php">サンプル依頼書一覧</a></li>
				<li><a href="sample_form.php">サンプル依頼書登録</a></li>
				<li><a href="ship_index.php">無償出荷一覧</a></li>
				<li><a href="ship_form.php">無償出荷登録</a></li>
				<li><a href="products_index.php">商品マスタ</a></li>
			</ul>
			<h3>サンプル依頼書参照</h3>
{{ if $mode != 'complete' }}
			<div class="clearfix">
				<h4 id="titleStatus">{{ $arr_status[$forms.status] }}</h4>
			</div>
{{ /if }}
{{ if $mode == 'preview' }}
			<p class="button">
				<button type="button" id="btn_preview" class="submit btn_preview"><span>印刷画面</span></button>
				
				<button type="button" id="btn_copy" class="submit btn_copy"><span>コピーして新規作成</span></button>
{{ if $forms.status == 1 || $forms.status == 3 || $forms.status == 4 || $forms.status == 9 }}
				<button type="button" id="btn_edit" class="submit btn_edit"><span>更新</span></button>
{{ /if }}
			</p>
{{ if $auth && $forms.status == 2 }}
			<p class="button">
				<button type="button" id="btn_approve_ng" class="submit btn_approve_ng"><span>非承認</span></button>
				<button type="button" id="btn_approve_ok" class="submit btn_approve_ok"><span>承認</span></button>
			</p>
{{ /if }}
			<form name="fm" action="sample_preview.php" method="post">
				<table class="formTable">
					<tbody>
						<tr>
							<th>作業状況</th>
							<td>{{ $arr_status[$forms.status] }}</td>
							<th>確定納期</th>
							<td>{{ $forms.settle_date }}</td>
						</tr>
					</tbody>
				</table>

				<table class="formTable">
					<tbody>
						<tr>
							<th>ID</th>
							<td>{{ $forms.disp_id }}</td>
							<th>登録日</th>
							<td>{{ $forms.r_date }}</td>
						</tr>
						<tr>
							<th>依頼者名</th>
							<td>{{ $forms.request_name }}</td>
							<th>更新日</th>
							<td>{{ $forms.u_date }}</td>
						</tr>
					</tbody>
				</table>

				<table id="inquiry_result" class="sortable">
					<thead>
						<tr>
							<th class="nosort"><h3>No.</h3></th>
							<th class="nosort"><h3>種類</h3></th>
							<th class="nosort"><h3>名称</h3></th>
							<th class="nosort"><h3>型番</h3></th>
							<th class="nosort"><h3>サイズ</h3></th>
							<th class="nosort"><h3>数量</h3></th>
							<th class="nosort"><h3>単位</h3></th>
							<th class="nosort"><h3>材料費</h3></th>
							<th class="nosort"><h3>目的/備考</h3></th>
						</tr>

					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td>{{ $category[$forms.category.1] }}</td>
							<td>{{ $products[$forms.products.1]|escape }}</td>
							<td>{{ $forms.model[1]|escape }}</td>
							<td>{{ $forms.size[1]|escape }}</td>
							<td>{{ $forms.amount[1] }}</td>
							<td>{{ $forms.unit[1] }}</td>
							<td>{{ $subtotal[1] }}</td>
							<td>{{ $forms.biko[1] }}</td>
						</tr>

						<tr>
							<td>2</td>
							<td>{{ $category[$forms.category.2] }}</td>
							<td>{{ $products[$forms.products.2]|escape }}</td>
							<td>{{ $forms.model[2]|escape }}</td>
							<td>{{ $forms.size[2]|escape }}</td>
							<td>{{ $forms.amount[2] }}</td>
							<td>{{ $forms.unit[2] }}</td>
							<td>{{ $subtotal[2] }}</td>
							<td>{{ $forms.biko[2] }}</td>
						</tr>

						<tr>
							<td>3</td>
							<td>{{ $category[$forms.category.3] }}</td>
							<td>{{ $products[$forms.products.3]|escape }}</td>
							<td>{{ $forms.model[3]|escape }}</td>
							<td>{{ $forms.size[3]|escape }}</td>
							<td>{{ $forms.amount[3] }}</td>
							<td>{{ $forms.unit[3] }}</td>
							<td>{{ $subtotal[3] }}</td>
							<td>{{ $forms.biko[3] }}</td>
						</tr>

						<tr>
							<td>4</td>
							<td>{{ $category[$forms.category.4] }}</td>
							<td>{{ $products[$forms.products.4]|escape }}</td>
							<td>{{ $forms.model[4]|escape }}</td>
							<td>{{ $forms.size[4]|escape }}</td>
							<td>{{ $forms.amount[4] }}</td>
							<td>{{ $forms.unit[4] }}</td>
							<td>{{ $subtotal[4] }}</td>
							<td>{{ $forms.biko[4] }}</td>
						</tr>

						<tr>
							<td>5</td>
							<td>{{ $category[$forms.category.5] }}</td>
							<td>{{ $products[$forms.products.5]|escape }}</td>
							<td>{{ $forms.model[5]|escape }}</td>
							<td>{{ $forms.size[5]|escape }}</td>
							<td>{{ $forms.amount[5] }}</td>
							<td>{{ $forms.unit[5] }}</td>
							<td>{{ $subtotal[5] }}</td>
							<td>{{ $forms.biko[5] }}</td>
						</tr>

						<tr>
							<td>6</td>
							<td>{{ $category[$forms.category.6] }}</td>
							<td>{{ $products[$forms.products.6]|escape }}</td>
							<td>{{ $forms.model[6]|escape }}</td>
							<td>{{ $forms.size[6]|escape }}</td>
							<td>{{ $forms.amount[6] }}</td>
							<td>{{ $forms.unit[6] }}</td>
							<td>{{ $subtotal[6] }}</td>
							<td>{{ $forms.biko[6] }}</td>
						</tr>

						<tr>
							<td>7</td>
							<td>{{ $category[$forms.category.7] }}</td>
							<td>{{ $products[$forms.products.7]|escape }}</td>
							<td>{{ $forms.model[7]|escape }}</td>
							<td>{{ $forms.size[7]|escape }}</td>
							<td>{{ $forms.amount[7] }}</td>
							<td>{{ $forms.unit[7] }}</td>
							<td>{{ $subtotal[7] }}</td>
							<td>{{ $forms.biko[7] }}</td>
						</tr>

						<tr>
							<td>8</td>
							<td>{{ $category[$forms.category.8] }}</td>
							<td>{{ $products[$forms.products.8]|escape }}</td>
							<td>{{ $forms.model[8]|escape }}</td>
							<td>{{ $forms.size[8]|escape }}</td>
							<td>{{ $forms.amount[8] }}</td>
							<td>{{ $forms.unit[8] }}</td>
							<td>{{ $subtotal[8] }}</td>
							<td>{{ $forms.biko[8] }}</td>
						</tr>

						<tr>
							<td>9</td>
							<td>{{ $category[$forms.category.9] }}</td>
							<td>{{ $products[$forms.products.9]|escape }}</td>
							<td>{{ $forms.model[9]|escape }}</td>
							<td>{{ $forms.size[9]|escape }}</td>
							<td>{{ $forms.amount[9] }}</td>
							<td>{{ $forms.unit[9] }}</td>
							<td>{{ $subtotal[9] }}</td>
							<td>{{ $forms.biko[9] }}</td>
						</tr>

						<tr>
							<td>10</td>
							<td>{{ $category[$forms.category.10] }}</td>
							<td>{{ $products[$forms.products.10]|escape }}</td>
							<td>{{ $forms.model[10]|escape }}</td>
							<td>{{ $forms.size[10]|escape }}</td>
							<td>{{ $forms.amount[10] }}</td>
							<td>{{ $forms.unit[10] }}</td>
							<td>{{ $subtotal[10] }}</td>
							<td>{{ $forms.biko[10] }}</td>
						</tr>
						
						<tr>
							<td colspan="5"></td>
							<th colspan="2">材料費合計</th>
							<td>{{ $all_total }}</td>
							<td></td>
						</tr>

					</tbody>
				</table>


				<table class="formTable">

					<tbody>
						<tr>
							<th>別途資料</th>
							<td>
								<ul>
									<li>{{ $forms.file1 }}{{ if $forms.file1 != '' }}：{{ /if }}<a href="download.php?id={{ $forms.id }}&no=1">{{ $forms.filename1 }}</a></li>
									<li>{{ $forms.file2 }}{{ if $forms.file2 != '' }}：{{ /if }}<a href="download.php?id={{ $forms.id }}&no=2">{{ $forms.filename2 }}</a></li>
									<li>{{ if $forms.file_memo != '' }}備考：{{ /if }}{{ $forms.file_memo }}</li>
								</ul>
								{{ $err.pro_name }}
							</td>
						</tr>

						<tr>
							<th>同梱物</th>
							<td>{{ $forms.item }}</td>
						</tr>

						<tr>
							<th>郵便番号</th>
							<td>{{ $forms.zipcode }}</td>
						</tr>

						<tr>
							<th>住所</th>
							<td>{{ $forms.address }}</td>
						</tr>

						<tr>
							<th>電話番号</th>
							<td>{{ $forms.tel }}</td>
						</tr>

						<tr>
							<th>会社名</th>
							<td>{{ $forms.company }}</td>
						</tr>

						<tr>
							<th>部署</th>
							<td>{{ $forms.division }}</td>
						</tr>

						<tr>
							<th>氏名</th>
							<td>{{ $forms.cust_name }}</td>
						</tr>

						<tr>
							<th>希望納期</th>
							<td>{{ $forms.request_date }}</td>
						</tr>

						<tr>
							<th>午前中指定</th>
							<td>{{ $specify[$forms.specify] }}
							</td>
						</tr>

						<tr>
							<th>特記事項</th>
							<td>{{ $forms.memo|nl2br }}</td>
						</tr>
					</tbody>
				</table>

				<table class="formTable">

					<tbody>
						<tr>
							<th>フォロー結果</th>
							<td>
								{{ $arr_result[$forms.follow_result] }}
							</td>
						</tr>
						<tr>
							<th>フォロー1</th>
							<td>
								{{ $forms.follow_date1 }}<br />
								{{ $forms.follow_text1 }}
							</td>
						</tr>
						<tr>
							<th>フォロー2</th>
							<td>
								{{ $forms.follow_date2 }}<br />
								{{ $forms.follow_text2 }}
							</td>
						</tr>
					</tbody>
				</table>

				<input type="hidden" name="status" value="" />
				<input type="hidden" name="id" value="{{ $forms.id }}" />
			</form>

			<p class="button">
				<button type="button" id="btn_preview" class="submit btn_preview"><span>印刷画面</span></button>
				<button type="button" id="btn_copy" class="submit btn_copy"><span>コピーして新規作成</span></button>
{{ if $forms.status == 1 || $forms.status == 3 || $forms.status == 9 }}
				<button type="button" id="btn_edit" class="submit btn_edit"><span>更新</span></button>
{{ /if }}
			</p>

{{ if $auth && $forms.status == 2 }}
			<p class="button">
				<button type="button" id="btn_approve_ng" class="submit btn_approve_ng"><span>非承認</span></button>
				<button type="button" id="btn_approve_ok" class="submit btn_approve_ok"><span>承認</span></button>
			</p>
{{ /if }}

{{ /if }}
{{ if $mode == 'complete' }}
			<p class="message">{{ $message }}</p>

			<ul>
				<li>&gt;&gt; <a href="javascript:open_preview();">印刷画面を表示</a></li>
				<li>&gt;&gt; <a href="sample_index.php">一覧へ戻る</a></li>
			</ul>
{{ /if }}

		</div></div>
		<address>Copyright (C) SHIFT Inc. / All rightes reserved</address>
	</body>

</html>